<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>选手列表</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  {include file="public/css"/}
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-card layui-col-md12">
          <div class="layui-card-header">
						选手列表
						<i class="layui-icon layui-icon-close" style="font-size:18px;font-weight:bold;cursor:pointer" onclick="closeself()"></i>
					</div>
          <div class="layui-card-body" pad15>
						<div class="layui-col-md4" style="padding-bottom:10px">
							<a class="layui-btn layuiadmin-btn-list" href="javascript:void(0)" onclick="openmax('{:url('joinedit')}&hid={$Request.param.hid}')">添加</a>
							<button class="layui-btn layui-btn-primary layuiadmin-btn-list" onclick="datadel(0)">删除</button>
							<button class="layui-btn layui-btn-primary layuiadmin-btn-list" onclick="setst(0,1)">通过</button>
							<button class="layui-btn layui-btn-primary layuiadmin-btn-list" onclick="setst(0,2)">驳回</button>
							<button class="layui-btn layui-btn-primary layuiadmin-btn-list" data-form-export="{:url('joinlistexcel')}/hid/{$Request.param.hid}">导出</button>
						</div>
						<div class="layui-form layui-col-md8 layui-form-search">
							{if !input('param.hid')}
							<div class="layui-inline">
								<label class="layui-form-label">活动</label>
								<div class="layui-input-inline" style="width:180px">
									<select name="hid" lay-filter="changehid">
										<option value="">全部</option>
										{foreach $toupiaoArr as $k=>$v}
										<option value="{$k}">{$v}</option>
										{/foreach}
									</select>
								</div>
							</div>
							{/if}

							<div class="layui-inline">
								<label class="layui-form-label">状态</label>
								<div class="layui-input-inline">
									<select name="status">
										<option value="">全部</option>
										<option value="0">待审核</option>
										<option value="1">已通过</option>
										<option value="2">已驳回</option>
									</select>
								</div>
							</div>
							<div class="layui-inline">
								<button class="layui-btn layuiadmin-btn-replys" lay-submit="" lay-filter="LAY-app-forumreply-search">
									<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
								</button>
							</div>
						</div>
						<div class="layui-col-md12">
							<table id="tabledata" lay-filter="tabledata"></table>
						</div>
          </div>
        </div>
    </div>
  </div>
	{include file="public/js"/}
	<script>
  var table = layui.table;
	var datawhere = {};
  //数据表
  var tableIns = table.render({
    elem: '#tabledata'
    ,url: '{$Request.url}' //数据接口
    ,page: true //开启分页
	,autoSort:false
    ,cols: [[ //表头
			{type:"checkbox"},
      {field: 'id', title: 'ID',  sort: true,width:80},
      {field: 'hdname', title: '所属活动'},
      {field: 'name', title: '选手名称'},
	  {field: 'number', title: '选手编号'},
	  {field: 'weixin', title: '联系方式'},
	  {field: 'banner', title: '选手主图',templet:function(d){
			return '<img src="'+d.pic+'" style="width:60px;height:auto"/>';
		}},
	  {field: 'helpnum', title: '累计票数',sort:true},
	  {field: 'readcount', title: '访问次数',sort:true},
	  {field: 'mingci', title: '排名'},
	  {foreach $formcontent as $k=>$field}
		  {if $field['key']!='separate'}
		  { field: 'form{$k}', title: "{$field['val1']}"
		  {if $field['key']=='upload'}
		  ,templet:function(d){
	  if(d.form{$k}){
		  return '<img src="'+d.form{$k}+'" style="width:50px" onclick="preview(this)"/>';
	  }else{
		  return '';
	  }
  }
  {/if}
	  {if $field['key']=='upload_file'}
  ,templet:function(d){
	  if(d.form{$k}){
		  return '<a href="'+d.form{$k}+'" style="width:50px" target="_blank" >点击下载查看</a>';
	  }else{
		  return '';
	  }
  }
	  {/if}
		  
				  {if $field['key']=='upload_pics'}
			  ,templet:function(d){
				  if(d.form{$k}){
					  var html = '';
					  var data = d.form{$k};
					  for (var i = 0; i<data.length; i++) {
						  html += '<img src="'+data[i]+'" style="width:50px" onclick="preview(this)"/>';
					  }
					  return html;
				  }else{
					  return '';
				  }
			  }
				  {/if}
					  
						  },
		{/if}
	{/foreach}
      {field: 'createtime', title: '参与时间',sort: true,templet:function(d){ return date('Y-m-d H:i',d.createtime)}},
      {field: 'status', title: '状态',width:80,templet:function(d){ 
				if(d.status==0){
						return '<button class="layui-btn layui-btn-sm" style="background-color:#f55">待审核</button>';
				}else if(d.status==1){
					return '<button class="layui-btn layui-btn-sm" style="background-color:#3e5">已通过</button>';
				}else if(d.status==2){
					return '<button class="layui-btn layui-btn-sm" style="background-color:#888">已驳回</button>';
				}
			}},
      {field: 'operation', title: '操作',templet: function(d){
				var html = '';
				html += '<button class="table-btn" onclick="openmax(\'{:url('joinedit')}&id='+d.id+'\')">编辑</button>';
				html += '<button class="table-btn" onclick="datadel('+d.id+')">删除</button>';
				html += '<button class="table-btn" onclick="openmax(\'{:url('helplist')}&joinid='+d.id+'\')">投票记录</button>';
				html += '<button class="table-btn" onclick="addpiao('+d.id+')">加票</button>';
				return html;
      }}
    ]]
  });
	//排序
	table.on('sort(tabledata)', function(obj){
		datawhere.field = obj.field;
		datawhere.order = obj.type;
		tableIns.reload({
			initSort: obj,
			where: datawhere
		});
	});
	//检索
	layui.form.on('submit(LAY-app-forumreply-search)', function(obj){
		var field = obj.field
		var olddatawhere = datawhere
		datawhere = field
		datawhere.field = olddatawhere.field
		datawhere.order = olddatawhere.order
		tableIns.reload({
			where: datawhere,
			page: {curr: 1}
		});
	})
	//删除
	function datadel(id){
		var ids = [];
		if(id==0){
			var checkStatus = table.checkStatus('tabledata')
			var checkData = checkStatus.data; //得到选中的数据
			if(checkData.length === 0){
				 return layer.msg('请选择数据');
			}
			for(var i=0;i<checkData.length;i++){
				ids.push(checkData[i]['id']);
			}
		}else{
			ids.push(id);
		}
		layer.confirm('确定要删除吗？删除后无法恢复！',{icon: 7, title:'操作确认'}, function(index){
			//do something
			layer.close(index);
			var index = layer.load();
			$.post("{:url('joinlistdel')}",{ids:ids},function(data){
				layer.close(index);
				dialog(data.msg,data.status);
				tableIns.reload()
			})
		});
	}
	//审核状态
	function setst(id,st){
		var ids = [];
		if(id==0){
			var checkStatus = table.checkStatus('tabledata')
			var checkData = checkStatus.data; //得到选中的数据
			if(checkData.length === 0){
				return layer.msg('请选择数据');
			}
			var ids = [];
			for(var i=0;i<checkData.length;i++){
				ids.push(checkData[i]['id']);
			}
		}else{
			ids.push(id)
		}

		if(st==2){
			var html = '';
			html+='	<div class="layui-form-item" style="margin-top:40px;margin-right:20px;">';
			html+='		<label class="layui-form-label" style="width:80px">驳回原因</label>';
			html+='		<div class="layui-input-inline" style="width:350px">';
			html+='			<input type="text" id="tuireason" class="layui-input"/>';
			html+='		</div>';
			html+='	</div>';

			var refundLayer = layer.open({type:1,area:['500px','250px'],title:false,content:html,shadeClose:true,btn: ['确定', '取消'],
				yes:function(){
					var index = layer.load();
					$.post("{:url('joinetst')}",{ids:ids,st:st,reason:$('#tuireason').val()},function(res){
						layer.close(index);
						dialog(res.msg,res.status);
						layer.close(refundLayer);
						tableIns.reload()
					})
				}
			})
		}else{
			layer.confirm('确定要审核通过吗?',{icon: 7, title:'操作确认'}, function(index){
				layer.close(index);
				var index = layer.load();
				$.post("{:url('joinetst')}",{ids:ids,st:st},function(data){
					layer.close(index);
					dialog(data.msg,data.status);
					tableIns.reload()
				});
			});
		}
	}
	function addpiao(id){
		var html = '';
		html+='	<div class="layui-form-item" style="margin-top:40px;margin-right:20px;">';
		html+='		<label class="layui-form-label" style="width:80px">增加票数：</label>';
		html+='		<div class="layui-input-inline" style="width:200px">';
		html+='			<input type="text" id="addpiao" class="layui-input"/>';
		html+='		</div>';
		html+='		<div class="layui-form-mid layui-word-aux"></div>';
		html+='	</div>';
		var addscoreLayer = layer.open({type:1,area:['500px','300px'],title:false,content:html,shadeClose:true,btn: ['确定', '取消'],
			yes:function(){
				var index = layer.load();
				$.post("{:url('addpiao')}",{id:id,num:$('#addpiao').val()},function(res){
					layer.close(index);
					dialog(res.msg,res.status);
					layer.close(addscoreLayer);
					tableIns.reload()
				})
			}
		})
	}
	</script>
	{include file="public/copyright"/}
</body>
</html>